# core/signal_hub.py
# 电话本：谁想换状态/换颜色，先在这里登记
_state_listener = []
_update_listener = []

def add_state_listener(func):
    _state_listener.append(func)

def fire_state_changed(new_state):
    for f in _state_listener:
        try:
            f(new_state)
        except Exception as e:
            print(f'[SIGNAL] 状态监听器执行失败: {e}')
            import traceback
            traceback.print_exc()

def fire_update_request():
    for f in _update_listener:
        f()

def register_update_callback(func):
    _update_listener.append(func)